package zry.Operate;

import zry.Achievement.*;
import zry.Achievement.Thesis.*;
import zry.Achievement.Reward.*;
import zry.Achievement.Standard.*;
import zry.Achievement.Other.*;
import zry.Achievement.Textbook.*;
import zry.Achievement.Patent.*;
import zry.Achievement.Report.*;
import zry.Achievement.Platform.*;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Scanner;

//提交成果认定申请
//拥有该权限的用户：学生
public class Apply {
    public void addApplyAchievement(String userid, String student_type) {
        if (student_type.contains("博士")) {
            label:
            while (true) {
                System.out.println("——————————————————————\n" +
                        "请输入要提交的成果类型" +
                        "1.论文" +
                        "2.奖励" +
                        "3.标准" +
                        "4.其他" +
                        "5.退出提交页面");
                Scanner scanner = new Scanner(System.in);
                String input = scanner.nextLine();
                switch (input) {
                    case "1":
                        addApplyThesis(userid);
                        break;
                    case "2":
                        addApplyReward(userid);
                        break;
                    case "3":
                        addApplyStandard(userid);
                        break;
                    case "4":
                        addApplyOther(userid);
                        break;
                    case "5":
                        break label;
                    default:
                        System.out.println("请输入1-5的数字");
                        break;
                }

            }

        } else if (student_type.contains("硕士")) {
            label:
            while (true) {
                System.out.println("——————————————————————\n" +
                        "请输入要提交的成果类型" +
                        "1.论文" +
                        "2.教材" +
                        "3.标准" +
                        "4.专利" +
                        "5.报告" +
                        "6.软硬件平台开发证明" +
                        "7.退出提交页面");
                Scanner scanner = new Scanner(System.in);
                String input = scanner.nextLine();
                switch (input) {
                    case "1":
                        addApplyThesis(userid);
                        break;
                    case "2":
                        addApplyTextbook(userid);
                        break;
                    case "3":
                        addApplyStandard(userid);
                        break;
                    case "4":
                        addApplyPatent(userid);
                        break;
                    case "5":
                        addApplyReport(userid);
                        break;
                    case "6":
                        addApplyPlatform(userid);
                        break;
                    case "7":
                        break label;
                    default:
                        System.out.println("请输入1-5的数字");
                        break;
                }
            }
        }
    }

    //提交论文的成果认定申请
    public void addApplyThesis(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("论文");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        ThesisDAO thesisDAO = new ThesisDAOImpl();
        Thesis thesis = new Thesis();
        thesis.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入论文名称");
        thesis.setT_name(scanner.nextLine());
        System.out.println("请输入刊物名称");
        thesis.setJ_name(scanner.nextLine());
        while (true) {
            System.out.println("请输入论文状态（1.录用未发表 2.已发表）");
            String input = scanner.nextLine();
            if (input.equals("1")) {
                thesis.setT_type("录用未发表");
                break;
            } else if (input.equals("2")) {
                thesis.setT_type("已发表");
                System.out.println("发布时间");
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    Date date = new Date(simpleDateFormat.parse(scanner.nextLine()).getTime());
                    thesis.setT_time(date);
                    break;
                } catch (Exception e) {
                    System.out.println("时间格式错误");
                }
            } else {
                System.out.println("请输入1-2的数字");
            }
        }
        System.out.println("请输入索引类型");
        thesis.setI_type(scanner.nextLine());
        System.out.println("请输入论文归属库");
        thesis.setL_type(scanner.nextLine());
        System.out.println("请输入佐证材料");
        thesis.setT_supporting(scanner.nextLine());
        if (thesisDAO.addThesis(thesis)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }

    //提交奖励的成果认定申请
    public void addApplyReward(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("奖励");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        RewardDAO rewardDAO = new RewardDAOImpl();
        Reward reward = new Reward();
        reward.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入奖励名称");
        reward.setR_name(scanner.nextLine());
        System.out.println("请输入奖励等级（国家级/省级···）");
        reward.setR_type(scanner.nextLine());
        System.out.println("请输入获奖等级（特等奖/一等奖/二等奖···）");
        reward.setR_level(scanner.nextLine());
        System.out.println("请输入排名（可以不输入，直接按回车键）");
        reward.setR_ranking(scanner.nextLine());
        while (true) {
            System.out.println("请输入获奖时间");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = new Date(simpleDateFormat.parse(scanner.nextLine()).getTime());
                reward.setR_time(date);
                break;
            } catch (Exception e) {
                System.out.println("时间格式错误");
            }
        }
        System.out.println("请输入佐证材料");
        reward.setR_supporting(scanner.nextLine());
        if (rewardDAO.addReward(reward)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }

    //提交标准的成果认定申请
    public void addApplyStandard(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("标准");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        StandardDAO standardDAO = new StandardDAOImpl();
        Standard standard = new Standard();
        standard.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入标准名称");
        standard.setS_name(scanner.nextLine());
        System.out.println("请输入标准等级（国家标准/省部级地方标准/行业标准/团队标准···）");
        standard.setS_type(scanner.nextLine());
        while (true) {
            System.out.println("请输入标准发布时间");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = new Date(simpleDateFormat.parse(scanner.nextLine()).getTime());
                standard.setS_time(date);
                break;
            } catch (Exception e) {
                System.out.println("时间格式错误");
            }
        }
        System.out.println("请输入佐证材料");
        standard.setS_supporting(scanner.nextLine());
        if (standardDAO.addStandard(standard)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }

    //提交其他成果的成果认定申请
    public void addApplyOther(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("其他");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        OtherDAO otherDAO = new OtherDAOImpl();
        Other other = new Other();
        other.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入其他成果名称");
        other.setO_name(scanner.nextLine());
        System.out.println("请输入内容");
        other.setO_content(scanner.nextLine());
        System.out.println("请输入佐证材料");
        other.setO_supporting(scanner.nextLine());
        if (otherDAO.addOther(other)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }

    //提交教材的成果认定申请
    public void addApplyTextbook(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("教材");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        TextbookDAO textbookDAO = new TextbookDAOImpl();
        Textbook textbook = new Textbook();
        textbook.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入教材名称");
        textbook.setT_name(scanner.nextLine());
        System.out.println("请输入教材出版社");
        textbook.setT_publisher(scanner.nextLine());
        while (true) {
            System.out.println("请输入教材出版时间");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = new Date(simpleDateFormat.parse(scanner.nextLine()).getTime());
                textbook.setT_time(date);
                break;
            } catch (Exception e) {
                System.out.println("时间格式错误");
            }
        }
        System.out.println("请输入贡献度");
        textbook.setT_contribution(scanner.nextLine());
        System.out.println("请输入佐证材料");
        textbook.setT_supporting(scanner.nextLine());
        if (textbookDAO.addTextbook(textbook)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }

    //提交专利的成果认定申请
    public void addApplyPatent(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("专利");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        PatentDAO patentDAO = new PatentDAOImpl();
        Patent patent = new Patent();
        patent.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入专利名称");
        patent.setP_name(scanner.nextLine());
        System.out.println("请输入专利类型");
        patent.setP_type(scanner.nextLine());
        System.out.println("请输入专利号");
        patent.setP_number(scanner.nextLine());
        while (true) {
            System.out.println("请输入专利发布时间");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = new Date(simpleDateFormat.parse(scanner.nextLine()).getTime());
                patent.setP_time(date);
                break;
            } catch (Exception e) {
                System.out.println("时间格式错误");
            }
        }
        System.out.println("请输入专利状态");
        patent.setP_status(scanner.nextLine());
        System.out.println("请输入贡献度");
        patent.setP_contribution(scanner.nextLine());
        System.out.println("请输入佐证材料");
        patent.setP_supporting(scanner.nextLine());
        if (patentDAO.addPatent(patent)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }

    //提交报告的成果认定申请
    public void addApplyReport(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("报告");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        ReportDAO reportDAO = new ReportDAOImpl();
        Report report = new Report();
        report.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入报告名称");
        report.setR_name(scanner.nextLine());
        System.out.println("请输入报告类型");
        report.setR_type(scanner.nextLine());
        System.out.println("请输入报告服务单位");
        report.setR_dept(scanner.nextLine());
        while (true) {
            System.out.println("请输入报告时间");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = new Date(simpleDateFormat.parse(scanner.nextLine()).getTime());
                report.setR_time(date);
                break;
            } catch (Exception e) {
                System.out.println("时间格式错误");
            }
        }
        System.out.println("请输入贡献度");
        report.setR_contribution(scanner.nextLine());
        System.out.println("请输入佐证材料");
        report.setR_supporting(scanner.nextLine());
        if (reportDAO.addReport(report)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }

    //提交软硬件平台开发证明的成果认定申请
    public void addApplyPlatform(String userid) {
        AchievementDAO achievementDAO = new AchievementDAOImpl();
        Achievement achievement = new Achievement();
        achievement.setA_type("平台");
        achievement.setS_id(userid);
        //添加achievement记录，并获取自增主键key
        String key = achievementDAO.addAchievement(achievement);

        PlatformDAO platformDAO = new PlatformDAOImpl();
        Platform platform = new Platform();
        platform.setA_id(key);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入平台名称");
        platform.setP_name(scanner.nextLine());
        System.out.println("请输入平台服务单位");
        platform.setP_dept(scanner.nextLine());
        while (true) {
            System.out.println("请输入平台上线时间");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = new Date(simpleDateFormat.parse(scanner.nextLine()).getTime());
                platform.setP_time(date);
                break;
            } catch (Exception e) {
                System.out.println("时间格式错误");
            }
        }
        System.out.println("请输入贡献度");
        platform.setP_contribution(scanner.nextLine());
        System.out.println("请输入佐证材料");
        platform.setP_supporting(scanner.nextLine());
        if (platformDAO.addPlatform(platform)) {
            System.out.println("申请提交成功");
        } else {
            System.out.println("申请有误，提交失败");
            //删除之前添加的achievement记录
            achievementDAO.deleteAchievement(key);
        }
    }
}
